<template>
    <div class="home-recommond">
        <h3>经典歌单</h3>
        <div class="wrapper" ref="wrapper">
            <ul class="content" ref="content">
                <li v-for="(item, index) in listData" :key="index">
                    <div class="cover">
                        <van-image :src="item.cover_url_small" radius="1rem" />
                        <span>{{ item.access_num | numFilter(1) }}万</span>
                    </div>
                    <span>{{ item.title }}</span>
                </li>
            </ul>
        </div>
    </div>
</template>
  
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js";
export default {
    data() {
        return {
            listData: [],
            id: 59,
            pageNo: 1,
            pageSize: 20,
        };
    },
    /**
     * 一个vue实例被生成后会调用created函数
     * 一般可以在此函数中调用ajax获取页面初始化所需的数据
     */
    created() {
        this.getSongListData(this.id, this.pageNo, this.pageSize);
    },

    methods: {
        //获取经典歌单数据
        getSongListData(id, pageNo, pageSize) {
            this.$request("get", "/recommend/playlist", {
                id,
                pageNo,
                pageSize,
            }).then((res) => {
                console.log(res);
                if (res.result == 100) {
                    this.listData = res.data.list;
                }
                // console.log(this.listData)
                //异步数据的一些处理s
                betterScrollHorizontal(
                    this,
                    this.$refs.wrapper,
                    this.$refs.content,
                    this.listData.length,
                    10
                );
            });
        },
    },
};
</script>
  
<style scoped>
/* .home-recommond > ul {
    display: flex;
    flex-wrap: wrap;
  }
  .home-recommond > ul > li {
    width: calc((100% - 1rem) / 3 * 1);
  }
  .home-recommond > ul > li:nth-of-type(3n + 2) {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
  } */
.cover {
    position: relative;
}

.cover>span {
    position: absolute;
    right: 0.2rem;
    bottom: 0.4rem;
    background-color: #a6a0a0;
    color: white;
    font-size: 14px;
    border-radius: 1rem;
    width: 5rem;
    display: inline-block;
}

.wrapper {
    width: 100%;
    /* 容器的宽度就是屏幕的宽度 */
    overflow: hidden;
}

/* content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
/* ul.content {
    width: calc(12 * 10rem);
  } */

ul.content li {
    /**li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
    display: inline-block;
    width: 10rem;
    vertical-align: top;
}

/* li里面有两个元素，div和span，所以使用通配符*     */
ul.content li * {
    margin: 0 0.1rem;
    /*里面的元素与li的边缘有个间距*/
}

ul.content>li>span {
    font-size: 0.8rem;
    color: #625858;
}
</style>>